package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.R;

import com.diudiutechnology.www.yadiudiu.util.http.HttpClient;
import com.diudiutechnology.www.yadiudiu.util.http.JsonTools;
import com.diudiutechnology.www.yadiudiu.util.http.OkHttpClientManager;
import com.diudiutechnology.www.yadiudiu.util.http.User;
import com.diudiutechnology.www.yadiudiu.util.http.UserCallback;
import com.diudiutechnology.www.yadiudiu.util.utils.Constant;
import com.diudiutechnology.www.yadiudiu.util.utils.ImgUtils;
import com.diudiutechnology.www.yadiudiu.util.utils.MyProgressDialog;
import com.diudiutechnology.www.yadiudiu.util.utils.PermissionsChecker;
import com.diudiutechnology.www.yadiudiu.util.utils.PictureUtil;
import com.diudiutechnology.www.yadiudiu.util.utils.SelectPhotoPop;
import com.diudiutechnology.www.yadiudiu.util.utils.SharedPreferencesUtil;
import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.util.utils.ToastUtils;
import com.diudiutechnology.www.yadiudiu.util.view.ListViewForScrollView;
import com.diudiutechnology.www.yadiudiu.util.view.UniversalPhotoPop;
import com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyActivity.BaseActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyActivity.LoginActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyApplication;
import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter.ReleaseActivityAdapter;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.MerchantsTypeModel;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.ReleaseModel;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.UniversalModel;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.http.RequestParams;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.model.PhotoInfo;
import okhttp3.Call;
import okhttp3.Response;

import static com.diudiutechnology.www.yadiudiu.R.array.model;

/**
 * Created by Administrator on 2017/8/17.
 * 我要发布
 */

public class ReleaseActivity extends BaseActivity implements View.OnClickListener {
    @Bind(R.id.retur)//返回
            LinearLayout retur;

    @Bind(R.id.title)//头部
            RelativeLayout title;

    @Bind(R.id.posted_layout)//图片
            RelativeLayout posted_layout;

    @Bind(R.id.modificon_img)//图片
            ImageView modificon_img;

    @Bind(R.id.modification_text)//图片数量
            TextView modification_text;
    @Bind(R.id.modification)//主题图片显示
            RelativeLayout modification;

    @Bind(R.id.release_listview)//Listview
            ListViewForScrollView releaseListview;

    @Bind(R.id.add_more_layout)//添加图文
            LinearLayout addMoreLayout;

    @Bind(R.id.payment_text)//付款方式
            TextView payment_text;
    @Bind(R.id.hall_room_text)//选择厅室
            TextView hall_room_text;
    @Bind(R.id.rent_way_text)//出租方式
            TextView rent_way_text;

    @Bind(R.id.fitment_text)//装修
            TextView fitment_text;
    @Bind(R.id.toward_text)//朝向
            TextView toward_text;
    @Bind(R.id.built_in_text)//建与
            TextView built_in_text;
    @Bind(R.id.use_text)//用途
            TextView use_text;
    @Bind(R.id.floor_text)//楼层
            TextView floor_text;

    @Bind(R.id.type_text)//类型
            TextView type_text;
    @Bind(R.id.community_text)//小区
            TextView community_text;

    @Bind(R.id.title_text)//标题
            EditText title_text;
    @Bind(R.id.monthly_rent_text)//租金
            EditText monthly_rent_text;
    @Bind(R.id.acreage_text)//面积
            EditText acreage_text;

    @Bind(R.id.summary_of_housing_text)//房源概述
            EditText summary_of_housing_text;
    @Bind(R.id.summary_of_housing_leng)//房源概述
            TextView summary_of_housing_leng;

    @Bind(R.id.button)//提交数据
            Button button;
    private Context context;
    private ReleaseActivityAdapter adapter;
    private List<ReleaseModel> buycarlist = new ArrayList<>();
    private List<ReleaseModel> pimglist = new ArrayList<>();
    private List<UniversalModel> unit = new ArrayList<>();//分类选项
    private List<UniversalModel> unit1 = new ArrayList<>();//分类选项
    private List<UniversalModel> unit2 = new ArrayList<>();//分类选项
    private String pos = "";
    private String posted = "";
    private int Judge = 0;//0、付款方式 1、选择厅室 2、出租 3、装修 4、朝向 5、建与 6、用途 7、楼层 8、类型 9、广告图片选择 10、图文图片
    private int Judge_img = 0;
    private View viewkre;
    private SelectPhotoPop selectPhotoPop;
    private DisplayImageOptions options;
    private ImageLoader imageLoader;
    public static ReleaseActivity activity;
    private MyProgressDialog mDialog;
    private String Judge_interface = "0";//判断哪个接口   0、上传图片
    private String longitude = "";
    private String latitude = "";
    private  String floors="";
    private  String id="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewkre = View.inflate(this, R.layout.activity_release, null);
        setContentView(viewkre);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        activity = this;
        context = this;
        if (getIntent() != null) {
            pos = getIntent().getStringExtra("pos");
            if (pos.equals("1")) {
                id = getIntent().getStringExtra("id");
            }
        }
        if (pos.equals("1")) {
            title.setVisibility(View.VISIBLE);
            retur.setOnClickListener(this);
            button.setText(getResources().getString(R.string.sure_to_modify));
            processshowcasing();
        }

        posted_layout.setOnClickListener(this);
        addMoreLayout.setOnClickListener(this);
        modificon_img.setOnClickListener(this);
        payment_text.setOnClickListener(this);
        hall_room_text.setOnClickListener(this);
        rent_way_text.setOnClickListener(this);
        fitment_text.setOnClickListener(this);
        toward_text.setOnClickListener(this);
        built_in_text.setOnClickListener(this);
        use_text.setOnClickListener(this);
        floor_text.setOnClickListener(this);
        type_text.setOnClickListener(this);
        community_text.setOnClickListener(this);
        button.setOnClickListener(this);
        adapter = new ReleaseActivityAdapter(this, buycarlist, 0);
        releaseListview.setAdapter(adapter);

        options = ImgUtils.imageOptions();
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        summary_of_housing_text.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String temp = editable.toString();
                summary_of_housing_leng.setText(temp.length()+"/500");
            }
        });
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.retur:
                finish();
                break;
            case R.id.payment_text://付款方式
            {
//                HashMap<String, String> params = new HashMap<>();
//                params.put("longitude", MyApplication.getInstance().getLongitude()+"");
//                params.put("latitude", MyApplication.getInstance().getLatitude()+"");
//                OkHttpClientManager.getInstance(context).postparams("CarBuying/index?p=1", params, callback);
                Judge = 0;
                unit.clear();
                unit1.clear();
                unit2.clear();
                String[] names = getResources().getStringArray(R.array.payment);
                UniversalModel model;
                for (int i = 0; i < names.length; i++) {
                    model = new UniversalModel();
                    model.setName(names[i]);
                    unit.add(model);
                }
                processunit();
            }
            break;
            case R.id.hall_room_text://选择厅室
            {
                Judge = 1;
                unit.clear();
                unit1.clear();
                unit2.clear();

                UniversalModel model;
                for (int i = 1; i < 10; i++) {
                    model = new UniversalModel();
                    model.setName(i + "室");
                    unit.add(model);
                }
                for (int i = 0; i < 10; i++) {
                    model = new UniversalModel();
                    model.setName(i + "厅");
                    unit1.add(model);
                }
                for (int i = 0; i < 10; i++) {
                    model = new UniversalModel();
                    model.setName(i + "卫");
                    unit2.add(model);
                }
                processunit();
            }
            break;
            case R.id.rent_way_text://出租
            {
                Judge = 2;
                unit.clear();
                unit1.clear();
                unit2.clear();
                String[] names = getResources().getStringArray(R.array.rent);
                UniversalModel model;
                for (int i = 0; i < names.length; i++) {
                    model = new UniversalModel();
                    model.setName(names[i]);
                    unit.add(model);
                }
                processunit();
            }
            break;
            case R.id.fitment_text://装修
            {
                Judge = 3;
                unit.clear();
                unit1.clear();
                unit2.clear();
                String[] names = getResources().getStringArray(R.array.fitment);
                UniversalModel model;
                for (int i = 0; i < names.length; i++) {
                    model = new UniversalModel();
                    model.setName(names[i]);
                    unit.add(model);
                }
                processunit();
            }
            break;
            case R.id.toward_text://朝向
            {
                Judge = 4;
                unit.clear();
                unit1.clear();
                unit2.clear();
                String[] names = getResources().getStringArray(R.array.toward);
                UniversalModel model;
                for (int i = 0; i < names.length; i++) {
                    model = new UniversalModel();
                    model.setName(names[i]);
                    unit.add(model);
                }
                processunit();
            }
            break;
            case R.id.built_in_text://建于
            {
                Judge = 5;
                unit.clear();
                unit1.clear();
                unit2.clear();
                UniversalModel model;
                Calendar c = Calendar.getInstance();//
                int year = c.get(Calendar.YEAR);
                for (int i = year + 20; i > 1940; i--) {
                    System.out.println("stringmd5result=" + i);
                    model = new UniversalModel();
                    model.setName(i + "");
                    unit.add(model);
                }
                processunit();
            }
            break;
            case R.id.use_text://用途
            {
                Judge = 6;
                unit.clear();
                unit1.clear();
                unit2.clear();

                String[] names = getResources().getStringArray(R.array.use);
                UniversalModel model;
                for (int i = 0; i < names.length; i++) {
                    model = new UniversalModel();
                    model.setName(names[i]);
                    unit.add(model);
                }
                processunit();
            }
            break;

            case R.id.floor_text://楼层
            {
                Judge = 7;
                unit.clear();
                unit1.clear();
                unit2.clear();

                UniversalModel model;
                for (int i = -2; i < 100; i++) {
                    model = new UniversalModel();
                    model.setName(i + "层");
                    unit.add(model);
                }
                for (int i = 1; i < 100; i++) {
                    model = new UniversalModel();
                    model.setName(i + "层");
                    unit1.add(model);
                }
                unit.remove(2);
                processunit();
            }
            break;
            case R.id.type_text://类型
            {
                Judge = 8;
                unit.clear();
                unit1.clear();
                unit2.clear();

                String[] names = getResources().getStringArray(model);
                UniversalModel model;
                for (int i = 0; i < names.length; i++) {
                    model = new UniversalModel();
                    model.setName(names[i]);
                    unit.add(model);
                }
                processunit();
            }
            break;
            case R.id.community_text://选择小区
            {
                Intent intent = new Intent(context, AddressSearchActivity.class);
                intent.putExtra("pos", "1");
                getParent().startActivityForResult(intent, Constant.ADDADDRESSENTAL);
            }
            break;

            case R.id.posted_layout://添加照片

                if (!PermissionsChecker.getPermissionsChecker(this, "0", 0)) {
                    if (!PermissionsChecker.getPermissionsChecker(this, "0", 2)) {
                        Judge = 9;
                        showSelectPicPop();
                    } else {
                        ToastUtils.show(context, "请检查是否打开储存权限");
                    }
                } else {
                    ToastUtils.show(context, "请检查是否打开相机权限");
                }

                break;

            case R.id.modificon_img://选择小区

                Intent intent = new Intent(context, GeneralPictureEditorActivity.class);
                intent.putExtra("pos", "2");
                intent.putExtra("Judge_posstr", "1");
                intent.putExtra("conumg", posted);
                getParent().startActivityForResult(intent, Constant.ADDRENTAL);

                break;
               /* 注释  相机*/
            case R.id.item_popupwindows_camera:
                selectPhotoPop.dismiss();
                GalleryFinal.openCamera(Constant.CAMERA, MyApplication.getInstance().initGalley(Constant.CAMERA, 1), mOnHanlderResultCallback);
                break;
            /* 注释  相册*/
            case R.id.item_popupwindows_Photo:
                selectPhotoPop.dismiss();
                GalleryFinal.openGallerySingle(Constant.GALLERYSINGLE, MyApplication.getInstance().initGalley(Constant.GALLERYSINGLE, 1), mOnHanlderResultCallback);
                break;
            /* 注释  取消*/
            case R.id.item_popupwindows_cancel:
                selectPhotoPop.dismiss();
                break;
            case R.id.add_more_layout:
                if (buycarlist.size() < 4) {
                    ReleaseModel models = new ReleaseModel();
                    models.setPicimga("");
                    models.setInstructiona("");
                    adapter.addItem(buycarlist.size(), models);
                    pimglist=buycarlist;
                } else {
                    ToastUtils.show(context, getResources().getString(R.string.please_illustrations));
                }
                break;
            case R.id.button:
                System.out.println("stringmd5result" + getjson());
                if (TextUtils.isEmpty(posted)) {//广告图
                    ToastUtils.show(context, getResources().getString(R.string.please_add_image));
                    return;
                }
                if (TextUtils.isEmpty(posted)) {//广告图
                    ToastUtils.show(context, getResources().getString(R.string.please_add_image));
                    return;
                }
                if (TextUtils.isEmpty(title_text.getText().toString().trim())) {//标题
                    ToastUtils.show(context, getResources().getString(R.string.please_title_name));
                    return;
                }
                if (TextUtils.isEmpty(monthly_rent_text.getText().toString().trim())) {//租金
                    ToastUtils.show(context, getResources().getString(R.string.please_monthly));
                    return;
                }
                if (TextUtils.isEmpty(payment_text.getText().toString().trim())) {//付款方式
                ToastUtils.show(context, getResources().getString(R.string.please_payment));
                return;
            }
                if (TextUtils.isEmpty(hall_room_text.getText().toString().trim())) {//厅室
                    ToastUtils.show(context, getResources().getString(R.string.please_hall_room));
                    return;
                }
                if (TextUtils.isEmpty(acreage_text.getText().toString().trim())) {//面积
                    ToastUtils.show(context, getResources().getString(R.string.please_acreage));
                    return;
                }
                if (TextUtils.isEmpty(rent_way_text.getText().toString().trim())) {//租住方式
                    ToastUtils.show(context, getResources().getString(R.string.please_rent_way));
                    return;
                }
                if (TextUtils.isEmpty(fitment_text.getText().toString().trim())) {//装修
                    ToastUtils.show(context, getResources().getString(R.string.please_fitment));
                    return;
                }
                if (TextUtils.isEmpty(toward_text.getText().toString().trim())) {//朝向
                    ToastUtils.show(context, getResources().getString(R.string.please_toward));
                    return;
                }
                if (TextUtils.isEmpty(floor_text.getText().toString().trim())) {//楼层
                    ToastUtils.show(context, getResources().getString(R.string.please_floor));
                    return;
                }
                if (TextUtils.isEmpty(use_text.getText().toString().trim())) {//用途
                    ToastUtils.show(context, getResources().getString(R.string.please_use));
                    return;
                }
                if (TextUtils.isEmpty(type_text.getText().toString().trim())) {//类型
                    ToastUtils.show(context, getResources().getString(R.string.please_type));
                    return;
                }
                if (TextUtils.isEmpty(built_in_text.getText().toString().trim())) {//建于
                    ToastUtils.show(context, getResources().getString(R.string.please_built_in));
                    return;
                }
                if (TextUtils.isEmpty(community_text.getText().toString().trim())) {//小区
                    ToastUtils.show(context, getResources().getString(R.string.please_community));
                    return;
                }
                if (TextUtils.isEmpty(summary_of_housing_text.getText().toString().trim())) {//概述
                    ToastUtils.show(context, getResources().getString(R.string.please_summary_of_housing));
                    return;
                }
                if (buycarlist.size()<=0) {//图文
                    ToastUtils.show(context, getResources().getString(R.string.please_caption));
                    return;
                }
               processdata();
                break;
        }
    }

    //图文图片
    public void processimg(int pos) {
        if (!PermissionsChecker.getPermissionsChecker(this, "0", 0)) {
            if (!PermissionsChecker.getPermissionsChecker(this, "0", 2)) {
                Judge_img = pos;
                Judge = 10;
                showSelectPicPop();
            } else {
                ToastUtils.show(context, "请检查是否打开储存权限");
            }
        } else {
            ToastUtils.show(context, "请检查是否打开相机权限");
        }
    }

    //图文删除
    public void processdeleting(int pos) {
        buycarlist.remove(pos);
        adapter.notifyDataSetChanged();
    }

    //绑定选项
    private void processunit() {
        UniversalPhotoPop typephoto = null;
        if (Judge == 7) {
            typephoto = new UniversalPhotoPop(context, unit, unit1, 1);
        } else if (Judge == 1) {
            typephoto = new UniversalPhotoPop(context, unit, unit1, unit2, 1);
        } else {
            typephoto = new UniversalPhotoPop(context, unit, 1);
        }
        typephoto.showAtLocation(viewkre, Gravity.BOTTOM, 0, 0);
        typephoto.setAddresskListener(new UniversalPhotoPop.OnAddressCListener() {
            @Override
            public void onClick(String province, String city, String area) {

                if (Judge == 0) {
                    payment_text.setText(province);
                } else if (Judge == 1) {
                    hall_room_text.setText(province + city + area);
                } else if (Judge == 2) {
                    rent_way_text.setText(province);
                } else if (Judge == 3) {
                    fitment_text.setText(province);
                } else if (Judge == 4) {
                    toward_text.setText(province);
                } else if (Judge == 5) {
                    built_in_text.setText(province);
                } else if (Judge == 6) {
                    use_text.setText(province);
                } else if (Judge == 7) {
                    int prov=Sundry.cutStringToInt(province,"层");
                    int cit=Sundry.cutStringToInt(city,"层");
                    if (prov>cit){
                        ToastUtils.show(context, getResources().getString(R.string.please_floors));
                        return;
                    }
                    floor_text.setText(province +"/"+ city);
                    floors=province + city;
                } else if (Judge == 8) {
                    type_text.setText(province);
                }
            }
        });
    }

    private GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback = new GalleryFinal.OnHanlderResultCallback() {
        @Override
        public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
            Bitmap bitmap = PictureUtil.decodeSampledBitmapFromFile(resultList.get(0).getPhotoPath(), Constant.WIDE, Constant.WIDE);
            String conimg = PictureUtil.saveBitmapFile(bitmap, String.valueOf(0));
            if (Judge == 9) {
                Intent intent = new Intent(context, GeneralPictureEditorActivity.class);
                intent.putExtra("pos", "2");
                intent.putExtra("Judge_posstr", "0");
                intent.putExtra("conumg", conimg);
                getParent().startActivityForResult(intent, Constant.ADDRENTAL);
            } else {
                processupload(conimg);
            }
        }

        @Override
        public void onHanlderFailure(int requestCode, String errorMsg) {

        }
    };

    public void processonactivity(int requestCode, int resultCode, Intent data) {
        System.out.println("stringmd5result=" + requestCode + "resultCode=" + resultCode);
        if (resultCode == Constant.ADDRENTAL) {

            posted = data.getStringExtra("posted");//图片集合
            String conumg = data.getStringExtra("conumg");// 首图
            String number = data.getStringExtra("number");// 首图
            if (TextUtils.isEmpty(posted)) {
                posted_layout.setVisibility(View.VISIBLE);
                modification.setVisibility(View.GONE);
            } else {
                posted_layout.setVisibility(View.GONE);
                modification.setVisibility(View.VISIBLE);
                imageLoader.displayImage(Constant.HTTP + conumg, modificon_img, options);
                modification_text.setText("编辑图片(" + number + "/6)");
            }
        } else if (resultCode == Constant.ADDADDRESSENTAL) {

            longitude = data.getStringExtra("longitude");//   经度
            latitude = data.getStringExtra("latitude");//  纬度
            String name = data.getStringExtra("name");//   经度
            String address = data.getStringExtra("address");//  纬度
            community_text.setText(name);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    //相册
    private void showSelectPicPop() {
        selectPhotoPop = new SelectPhotoPop(this, this);
        selectPhotoPop.showAtLocation(viewkre, Gravity.BOTTOM, 0, 0);
    }

    //上传图片
    private void processupload(String upload) {
        if (Sundry.isOpenNetwork(context)) {
            Judge_interface = "0";
            mDialog = new MyProgressDialog(context);
            //HttpClient.upload(upload, this);
            HashMap<String, String> params = new HashMap<>();
            params.put("name", "pic");
         //   OkHttpClientManager.getInstance(context).postfile(Constant.NORMUPLOAD, params, new File(upload), callback);
        } else {
            ToastUtils.Toastshow(context, getResources().getString(R.string.network));
        }
    }

    //上传
    private void processdata() {
        if (Sundry.isOpenNetwork(context)) {
            Judge_interface = "1";
            mDialog = new MyProgressDialog(context);
           HashMap<String, String> params = new HashMap<>();
//            RequestParams params = new RequestParams(Constant.COM + Constant.RENTOUTCOMMENTRENT);
//            params.addBodyParameter("pic", posted);
//            params.addBodyParameter("uid", SharedPreferencesUtil.getString(SharedPreferencesUtil.Keys.USERID_KEYS, ""));
//            params.addBodyParameter("title", title_text.getText().toString().trim());
//            params.addBodyParameter("mnthly", monthly_rent_text.getText().toString().trim());
//            params.addBodyParameter("payment", payment_text.getText().toString().trim());
//            params.addBodyParameter("room", hall_room_text.getText().toString().trim());
//            params.addBodyParameter("area", acreage_text.getText().toString().trim());
//            params.addBodyParameter("rnovation", fitment_text.getText().toString().trim());
//            params.addBodyParameter("toward", toward_text.getText().toString().trim());
//            params.addBodyParameter("floor", floor_text.getText().toString().trim());
//            params.addBodyParameter("use", use_text.getText().toString().trim());
//            params.addBodyParameter("type", type_text.getText().toString().trim());
//            params.addBodyParameter("bilttime", built_in_text.getText().toString().trim());
//            params.addBodyParameter("reasetime", "");
//            params.addBodyParameter("community", community_text.getText().toString().trim());
//            params.addBodyParameter("text", summary_of_housing_text.getText().toString().trim());
//            params.addBodyParameter("mode", rent_way_text.getText().toString().trim());
//            params.addBodyParameter("longitude", longitude);
//            params.addBodyParameter("latitude", latitude);
//            params.addBodyParameter("verifiToken", Sundry.getMD5(SharedPreferencesUtil.getString(SharedPreferencesUtil.Keys.TOKEN_KEYS, "") + Constant.PRICODE));
//            params.addBodyParameter("teristic", getjson());
            params.put("pic", posted);
            params.put("uid", SharedPreferencesUtil.getString(SharedPreferencesUtil.Keys.USERID_KEYS, ""));
            params.put("title", title_text.getText().toString().trim());
            params.put("mnthly", monthly_rent_text.getText().toString().trim());
            params.put("payment", payment_text.getText().toString().trim());
            params.put("room", hall_room_text.getText().toString().trim());
            params.put("area", acreage_text.getText().toString().trim());
            params.put("rnovation", fitment_text.getText().toString().trim());
            params.put("toward", toward_text.getText().toString().trim());
            params.put("floor", floors);
            params.put("use", use_text.getText().toString().trim());
            params.put("type", type_text.getText().toString().trim());
            params.put("bilttime", built_in_text.getText().toString().trim());
            params.put("reasetime", "");
            params.put("community", community_text.getText().toString().trim());
            params.put("text", summary_of_housing_text.getText().toString().trim());
            params.put("mode", rent_way_text.getText().toString().trim());
            params.put("longitude", longitude);
            params.put("latitude", latitude);
            params.put("verifiToken", Sundry.getMD5(SharedPreferencesUtil.getString(SharedPreferencesUtil.Keys.TOKEN_KEYS, "") + Constant.PRICODE));
            params.put("teristic", getjson());
//            HttpClient.testing(params, new org.xutils.common.Callback.CommonCallback<String>() {
//                @Override
//                public void onSuccess(String result) {
//                    if (mDialog != null) {
//                        mDialog.dismiss();
//                    }
//                    System.out.println("stringmd5result"+ result);
//                }
//
//                @Override
//                public void onError(Throwable ex, boolean isOnCallback) {
//                    if (mDialog != null) {
//                        mDialog.dismiss();
//                    }
//                    System.out.println("stringmd5result"+ ex.toString());
//                }
//
//                @Override
//                public void onCancelled(CancelledException cex) {
//                    if (mDialog != null) {
//                        mDialog.dismiss();
//                    }
//                    System.out.println("stringmd5result"+ cex.toString());
//                }
//
//                @Override
//                public void onFinished() {
//
//                }
//            });
           // OkHttpClientManager.getInstance(context).postparams(Constant.RENTOUTCOMMENTRENT, params, callback);

        } else {
            ToastUtils.Toastshow(context, getResources().getString(R.string.network));
        }
    }

    //修改展示
    private void processshowcasing() {
        if (Sundry.isOpenNetwork(context)) {
            Judge_interface = "2";
            mDialog = new MyProgressDialog(context);
            HashMap<String, String> params = new HashMap<>();
            params.put("id", id);
            params.put("userid", SharedPreferencesUtil.getString(SharedPreferencesUtil.Keys.USERID_KEYS, ""));
            params.put("verifiToken", Sundry.getMD5(SharedPreferencesUtil.getString(SharedPreferencesUtil.Keys.TOKEN_KEYS, "") + Constant.PRICODE));
         //   OkHttpClientManager.getInstance(context).postparams(Constant.RENTOUTXGRENT, params, callback);
        } else {
            ToastUtils.Toastshow(context, getResources().getString(R.string.network));
        }
    }
    private String getjson() {
        String json = "";
        JSONArray jsonArray = new JSONArray();
        try {
            for (int i = 0; i < buycarlist.size(); i++) {
                ReleaseModel releaseModel = buycarlist.get(i);
                JSONObject jsonObject3 = new JSONObject();
                jsonObject3.put("picimga", releaseModel.getPicimga());
                jsonObject3.put("instructiona", releaseModel.getInstructiona());
                jsonArray.put(jsonObject3);
            }
            json = jsonArray.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }

    Callback<String> callback = new Callback<String>() {
        @Override
        public String parseNetworkResponse(Response response, int id) throws Exception {
            String string = response.body().string();
            return string;
        }

        @Override
        public void onError(Call call, Exception e, int id) {
            if (mDialog != null) {
                mDialog.dismiss();
            }
            System.out.println("stringmd5result"+ e.toString());
            ToastUtils.Toastshow(context, getResources().getString(R.string.server));
        }

        @Override
        public void onResponse(String response, int id) {
            if (mDialog != null) {
                mDialog.dismiss();
            }
            System.out.println("stringmd5result" + response);
            List<MerchantsTypeModel> getnote = JsonTools.getmerchanttype(response);
            if (getnote != null || getnote.size() > 0) {
                String error = getnote.get(0).getError();
                String mssage = getnote.get(0).getMssage();
                if (error.equals("200")) {
                    String content = getnote.get(0).getResult();
                    if (Judge_interface.equals("0")) {//图片
                        System.out.println("stringmd5result=pimglist=" + pimglist.size()+"Judge_img="+Judge_img);

//                        ReleaseModel models = new ReleaseModel();
//                        models.setPicimga(content);
//                        models.setInstructiona("");
//                        adapter.addItem(Judge_img, models);
                        List<ReleaseModel> list=new ArrayList<>();
                        for (int i=0;i<pimglist.size();i++){
                            ReleaseModel releaseModel = pimglist.get(i);
                            if (i==Judge_img){
                                releaseModel.setPicimga(content);
                            }
                            list.add(releaseModel);
                        }
                     adapter.addimg(list);
                    } else if (Judge_interface.equals("1")) {// 上传数据
                        processEmpty();
                        RentalHouseActivity ac=new RentalHouseActivity();
                        ac.activity.setCurrentItem();
                    }else if ( Judge_interface.equals("2")){

                    }
                } else if (error.equals("105")) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    startActivity(intent);
                    ToastUtils.show(context, mssage);
                } else {
                    ToastUtils.show(context, mssage);
                }
            }
        }
    };
//清空
private void processEmpty (){
    posted="";
    title_text.setText("");
    monthly_rent_text.setText("");
    payment_text.setText("");
    hall_room_text.setText("");
    acreage_text.setText("");
    fitment_text.setText("");
    toward_text.setText("");
    floor_text.setText("");
    use_text.setText("");
    floors="";
    type_text.setText("");
    built_in_text.setText("");
    community_text.setText("");
    summary_of_housing_text.setText("");
    rent_way_text.setText("");
    longitude="";
    latitude="";
    buycarlist.clear();
}
}
